<?php
/**
 * FFoto.php
 * @package Foundation
 *
 */
/**
 * FFoto
 * @package Foundation
 * @author mw
 *
 */
class FFoto extends Fdatabase {
	/**
	 * Costruttore
	 */
	public function __construct() {
		parent::__construct('EFoto','foto',array('id'));
	}
	/**
	 * Prende le foto degli iscritti
	 * @param string $username
	 * @param unknown_type $limit
	 */
	public function getFotoIscritti($username,$limit){
		
		$query = 'SELECT * 
				  FROM foto 
				  WHERE username IN (
    			  	SELECT iscritto.iscritto 
    			  	FROM iscritto 
    			  	WHERE username = "'.$this->safeString($username).'")
				  ORDER BY foto.id DESC
				  LIMIT 0,'.$limit.';';
		
		$this->_query($query);
	}
	/**
	 *  Prende le foto degli amici
	 * @param string $username
	 * @param unknown_type $limit
	 */
	public function getFotoAmici($username,$limit){
	
		$query = 'SELECT *
				  FROM foto
		 		  WHERE username IN (
					SELECT amico.amico2
					FROM amico
					WHERE amico1 = "'.$this->safeString($username).'" AND confermato = 1)
				  ORDER BY foto.id DESC
				  LIMIT 0,'.$limit.';';
	
		$this->_query($query);
	}
	/**
	 * Prende una foto a caso
	 */
	public function getFotoRand(){
		$query = 'SELECT *
				  FROM foto
				  ORDER BY RAND()
				  LIMIT 1;';
		$this->_query($query);
	}
}